package com.apes.hr.transfer.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.transfer.model.TransferApplicationExecution;

import java.util.Date;

import com.apes.hr.transfer.model.TransferApplicationItem;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
/**
 * @author Fengjiajing
 * @create 2018-07-31 10:07
 */
public interface TransferApplicationExecutionRepository extends CustomRepository<TransferApplicationExecution, Date>{



    @Query("select T from TransferApplicationExecution T where effectiveDate >= ?1 and effectiveDate < ?2")
    List<TransferApplicationExecution> findByEffectiveDate(@Param("dTomorrow") Date dTomorrow, @Param("dAfterTomorrow")Date dAfterTomorrow);

    @Query(value = "select T.* from hr_transfer_execution T,hr_transfer_application_item a WHERE a.id = t.transfer_application_item_id AND a.repeal=0 And t.end_date >= ?1 and t.end_date <?2 ",nativeQuery = true)
    List<TransferApplicationExecution> findByEndDate(@Param("dToday") Date dTodyay, @Param("dTomorrow")Date dTomorrow);

    @Query(value = "SELECT T.*, T.ROWID FROM HR_TRANSFER_EXECUTION T WHERE T.TRANSFER_APPLICATION_ITEM_ID = ?1",nativeQuery = true)
    TransferApplicationExecution findByTransferApplicationItems(TransferApplicationItem item);

    //查询当天下午生效的
    @Query("select T from TransferApplicationExecution T where effectiveDate >= ?1 and effectiveDate <= ?2")
    List<TransferApplicationExecution> findByEffectiveDateTodayNoon(@Param("today") Date today, @Param("todayNoon")Date todayNoon);

}
